Function to calculate the scaling factor sigma
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(self_organizing_map) | :: | kohonen_map |
A |
|||
real(kind=wp), | intent(inout), | dimension(:,:) | :: | input_data |
A real array with the input data |
|
integer, | intent(inout), | optional | :: | seed |
An integer with the random seed |
A real variable with the value of sigma
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | ndat | ||||
integer, | public | :: | nvar | ||||
integer, | public | :: | seed1 | ||||
integer, | public | :: | nx | ||||
integer, | public | :: | ny | ||||
integer, | public | :: | nz | ||||
integer, | public | :: | nxyz | ||||
integer, | public | :: | ierr | ||||
integer, | public | :: | i | ||||
integer, | public | :: | j | ||||
real(kind=wp), | public, | allocatable | :: | sample_pos(:) | |||
real(kind=wp), | public, | allocatable | :: | p_vector(:,:) | |||
real(kind=wp), | public, | allocatable | :: | sigma_table(:,:) | |||
real(kind=wp), | public, | allocatable | :: | current_sigma(:) | |||
integer, | public, | allocatable | :: | sample_index(:) | |||
type(quicksort), | public | :: | qsort |
function calculate_sigma(kohonen_map,input_data,seed) result(sigma) !======================================================================================== !! Function to calculate the scaling factor sigma class(self_organizing_map) :: kohonen_map !! A `self_organizing_map` object real(kind=wp),dimension(:,:),intent(inout) :: input_data !! A real array with the input data integer,intent(inout),optional :: seed !! An integer with the random seed real(kind=wp) :: sigma !! A real variable with the value of sigma integer :: ndat,nvar,seed1,nx,ny,nz,nxyz,ierr,i,j real(kind=wp),allocatable :: sample_pos(:),p_vector(:,:),sigma_table(:,:) real(kind=wp),allocatable :: current_sigma(:) integer,allocatable :: sample_index(:) type(quicksort) :: qsort ! if(.not. present(seed)) then seed1=12345; else seed1=seed; endif ! ndat=size(input_data,1); nvar=size(input_data,2); ! !kohonen_map%parameters=training_parameters(1); nx=kohonen_map%parameters%number_nodes_nx; ny=kohonen_map%parameters%number_nodes_ny; nz=kohonen_map%parameters%number_nodes_nz; nxyz=nx*ny*nz; allocate(sample_pos(ndat),stat=ierr); allocate(sample_index(ndat),stat=ierr); allocate(p_vector(nxyz,nvar),stat=ierr); allocate(sigma_table(ndat,nxyz),stat=ierr); allocate(current_sigma(ndat),stat=ierr); !call sgrnd(seed1); do i=1,size(sample_pos); sample_pos(i)=kohonen_map%rnumber_grator%generate(); enddo !call grnd_array(sample_pos); do i=1,nxyz sample_index(i)=i; enddo ! call qsort%sort(sample_pos,sample_index); ! ! define p vector (See Lopez-Rubio et al, 2015) ! p_vector(1:nxyz,1:nvar)=input_data(sample_index(1:nxyz),1:nvar); ! ! Calculate the distance between the input data and the selected prototypes ! do i=1,ndat do j=1,nxyz sigma_table(i,j)=sum((input_data(i,:)-p_vector(j,:))**2); enddo enddo ! do j=1,nxyz current_sigma(1:ndat)=sigma_table(1:ndat,j); !(sample_index(i)=i,i=1,ndat) call qsort%sort(current_sigma,sample_index); ! if(current_sigma(1) > 1d-10) then ! current_sigma_value() enddo ! deallocate(sample_pos,sample_index,p_vector,sigma_table,current_sigma); ! end function calculate_sigma